package com.hkw.utils;

import com.hkw.model.Student;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * ResultSetHandler接口的实现类，返回一个封装好的Student
 */
public class StudentHandler implements ResultSetHandler<Student> {
    Student student = null;
    @Override
    public Student handle(ResultSet resultSet) throws SQLException {
        while(resultSet.next()) {
            student = new Student();
            student.setId(resultSet.getInt("id"));
            student.setBirthday(resultSet.getDate("birth").toString());
            student.setEmail(resultSet.getString("email"));
            student.setName(resultSet.getString("name"));
            student.setClassId(resultSet.getInt("classId"));
            student.setSex(resultSet.getString("sex"));
            student.setRemark(resultSet.getString("remark"));
        }
        return student;
    }
}
